package com.machine.filling.Test;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.machine.filling.R;
import com.machine.filling.db.dao.CardTempDao;
import com.machine.filling.db.dao.ClientInfoDao;
import com.machine.filling.db.dao.GunInfoDao;
import com.machine.filling.db.greendao.CardTempModleDao;
import com.machine.filling.db.greendao.GunInfoModleDao;
import com.machine.filling.db.modle.CardTempModle;
import com.machine.filling.db.modle.GunInfoModle;
import com.machine.filling.function.splish.SplishActivity;

/**
 * Created by Administrator on 2018/3/28 0028.
 */
@Deprecated
public class TestMainFragment extends Fragment implements View.OnClickListener {

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = View.inflate(getContext(), R.layout.fg_test_main, null);
        initView(view);
        initData();
        return view;
    }

    private void initView(View view) {
        view.findViewById(R.id.bt_http).setOnClickListener(this);
        view.findViewById(R.id.bt_port).setOnClickListener(this);
        view.findViewById(R.id.bt_finish).setOnClickListener(this);
        view.findViewById(R.id.bt_machine).setOnClickListener(this);
        view.findViewById(R.id.bt_del_db).setOnClickListener(this);
    }

    private void initData() {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bt_http:
                changeFg.changeHttp(getActivity());
                break;
            case R.id.bt_port:
                changeFg.changePort(getActivity());
                break;
            case R.id.bt_finish:
                getActivity().finish();
                break;
            case R.id.bt_machine:
                getActivity().startActivity(new Intent(getActivity(), SplishActivity.class));
                break;
            case R.id.bt_del_db:
                GunInfoDao.getInstance().deleteAll();
                ClientInfoDao.getInstance().deleteAll();
                CardTempDao.getInstance().deleteAll();
                break;
        }
    }

    private ChangeFg changeFg;

    public void setChangeFg(ChangeFg changeFg) {
        this.changeFg = changeFg;
    }

    public interface ChangeFg {
        void changeHttp(FragmentActivity activity);

        void changePort(FragmentActivity activity);
    }
}
